package cn.iocoder.yudao.module.system.dal.mysql.subjectcombination;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.subjectcombination.vo.SubjectCombinationPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.subjectcombination.SubjectCombinationDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 选科组合 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface SubjectCombinationMapper extends BaseMapperX<SubjectCombinationDO> {

    default PageResult<SubjectCombinationDO> selectPage(SubjectCombinationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SubjectCombinationDO>()
                .likeIfPresent(SubjectCombinationDO::getCombinationCode, reqVO.getCombinationCode())
                .likeIfPresent(SubjectCombinationDO::getCombinationName, reqVO.getCombinationName())
                .eqIfPresent(SubjectCombinationDO::getCategory, reqVO.getCategory())
                .eqIfPresent(SubjectCombinationDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(SubjectCombinationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SubjectCombinationDO::getId));
    }

    default List<SubjectCombinationDO> selectList(SubjectCombinationPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<SubjectCombinationDO>()
                .likeIfPresent(SubjectCombinationDO::getCombinationCode, reqVO.getCombinationCode())
                .likeIfPresent(SubjectCombinationDO::getCombinationName, reqVO.getCombinationName())
                .eqIfPresent(SubjectCombinationDO::getCategory, reqVO.getCategory())
                .eqIfPresent(SubjectCombinationDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(SubjectCombinationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SubjectCombinationDO::getId));
    }

    /**
     * 根据组合编码查询
     *
     * @param combinationCode 组合编码
     * @return 选科组合
     */
    default SubjectCombinationDO selectByCombinationCode(String combinationCode) {
        return selectOne(SubjectCombinationDO::getCombinationCode, combinationCode);
    }

    /**
     * 根据类别查询启用的组合
     *
     * @param category 类别
     * @return 选科组合列表
     */
    default List<SubjectCombinationDO> selectEnabledByCategory(String category) {
        return selectList(new LambdaQueryWrapperX<SubjectCombinationDO>()
                .eq(SubjectCombinationDO::getCategory, category)
                .eq(SubjectCombinationDO::getStatus, 1)
                .orderByAsc(SubjectCombinationDO::getSortOrder));
    }

    /**
     * 查询所有启用的组合
     *
     * @return 选科组合列表
     */
    default List<SubjectCombinationDO> selectAllEnabled() {
        return selectList(new LambdaQueryWrapperX<SubjectCombinationDO>()
                .eq(SubjectCombinationDO::getStatus, 1)
                .orderByAsc(SubjectCombinationDO::getSortOrder));
    }

    /**
     * 根据科目查询包含该科目的组合
     *
     * @param subjectName 科目名称
     * @return 选科组合列表
     */
    default List<SubjectCombinationDO> selectBySubject(String subjectName) {
        return selectList(new LambdaQueryWrapperX<SubjectCombinationDO>()
                .like(SubjectCombinationDO::getSubjects, subjectName)
                .eq(SubjectCombinationDO::getStatus, 1)
                .orderByAsc(SubjectCombinationDO::getSortOrder));
    }

}